/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package warmachineroster.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

import warmachineroster.Roster;
import warmachineroster.RosterElement;
import warmachineroster.WarmachinerosterPackage;

import warmachinesystem.ArmyList;
import warmachinesystem.BaseUnit;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Roster</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link warmachineroster.impl.RosterImpl#getArmyList <em>Army List</em>}</li>
 *   <li>{@link warmachineroster.impl.RosterImpl#getRosterUnits <em>Roster Units</em>}</li>
 *   <li>{@link warmachineroster.impl.RosterImpl#getName <em>Name</em>}</li>
 *   <li>{@link warmachineroster.impl.RosterImpl#getPointValue <em>Point Value</em>}</li>
 *   <li>{@link warmachineroster.impl.RosterImpl#getMaxPointValue <em>Max Point Value</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class RosterImpl extends EObjectImpl implements Roster {
	/**
	 * The cached value of the '{@link #getArmyList() <em>Army List</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getArmyList()
	 * @generated
	 * @ordered
	 */
	protected ArmyList armyList;

	/**
	 * The cached value of the '{@link #getRosterUnits() <em>Roster Units</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getRosterUnits()
	 * @generated
	 * @ordered
	 */
	protected EList<RosterElement> rosterUnits;

	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * The default value of the '{@link #getPointValue() <em>Point Value</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPointValue()
	 * @generated
	 * @ordered
	 */
	protected static final int POINT_VALUE_EDEFAULT = 0;

	/**
	 * The default value of the '{@link #getMaxPointValue() <em>Max Point Value</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMaxPointValue()
	 * @generated
	 * @ordered
	 */
	protected static final int MAX_POINT_VALUE_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getMaxPointValue() <em>Max Point Value</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getMaxPointValue()
	 * @generated
	 * @ordered
	 */
	protected int maxPointValue = MAX_POINT_VALUE_EDEFAULT;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected RosterImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return WarmachinerosterPackage.Literals.ROSTER;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ArmyList getArmyList() {
		if (armyList != null && armyList.eIsProxy()) {
			InternalEObject oldArmyList = (InternalEObject)armyList;
			armyList = (ArmyList)eResolveProxy(oldArmyList);
			if (armyList != oldArmyList) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, WarmachinerosterPackage.ROSTER__ARMY_LIST, oldArmyList, armyList));
			}
		}
		return armyList;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public ArmyList basicGetArmyList() {
		return armyList;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setArmyList(ArmyList newArmyList) {
		ArmyList oldArmyList = armyList;
		armyList = newArmyList;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, WarmachinerosterPackage.ROSTER__ARMY_LIST, oldArmyList, armyList));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<RosterElement> getRosterUnits() {
		if (rosterUnits == null) {
			rosterUnits = new EObjectContainmentEList<RosterElement>(RosterElement.class, this, WarmachinerosterPackage.ROSTER__ROSTER_UNITS);
		}
		return rosterUnits;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, WarmachinerosterPackage.ROSTER__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated NOT
	 */
	public int getPointValue() {
		int pointValue = 0;
		for (RosterElement element : getRosterUnits()){
			pointValue += element.getPointCost();
		}
		return pointValue;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getMaxPointValue() {
		return maxPointValue;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setMaxPointValue(int newMaxPointValue) {
		int oldMaxPointValue = maxPointValue;
		maxPointValue = newMaxPointValue;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, WarmachinerosterPackage.ROSTER__MAX_POINT_VALUE, oldMaxPointValue, maxPointValue));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public boolean canAdd(BaseUnit baseUnit) {
		// TODO: implement this method
		// Ensure that you remove @generated or mark it @generated NOT
		throw new UnsupportedOperationException();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case WarmachinerosterPackage.ROSTER__ROSTER_UNITS:
				return ((InternalEList<?>)getRosterUnits()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case WarmachinerosterPackage.ROSTER__ARMY_LIST:
				if (resolve) return getArmyList();
				return basicGetArmyList();
			case WarmachinerosterPackage.ROSTER__ROSTER_UNITS:
				return getRosterUnits();
			case WarmachinerosterPackage.ROSTER__NAME:
				return getName();
			case WarmachinerosterPackage.ROSTER__POINT_VALUE:
				return getPointValue();
			case WarmachinerosterPackage.ROSTER__MAX_POINT_VALUE:
				return getMaxPointValue();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case WarmachinerosterPackage.ROSTER__ARMY_LIST:
				setArmyList((ArmyList)newValue);
				return;
			case WarmachinerosterPackage.ROSTER__ROSTER_UNITS:
				getRosterUnits().clear();
				getRosterUnits().addAll((Collection<? extends RosterElement>)newValue);
				return;
			case WarmachinerosterPackage.ROSTER__NAME:
				setName((String)newValue);
				return;
			case WarmachinerosterPackage.ROSTER__MAX_POINT_VALUE:
				setMaxPointValue((Integer)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case WarmachinerosterPackage.ROSTER__ARMY_LIST:
				setArmyList((ArmyList)null);
				return;
			case WarmachinerosterPackage.ROSTER__ROSTER_UNITS:
				getRosterUnits().clear();
				return;
			case WarmachinerosterPackage.ROSTER__NAME:
				setName(NAME_EDEFAULT);
				return;
			case WarmachinerosterPackage.ROSTER__MAX_POINT_VALUE:
				setMaxPointValue(MAX_POINT_VALUE_EDEFAULT);
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case WarmachinerosterPackage.ROSTER__ARMY_LIST:
				return armyList != null;
			case WarmachinerosterPackage.ROSTER__ROSTER_UNITS:
				return rosterUnits != null && !rosterUnits.isEmpty();
			case WarmachinerosterPackage.ROSTER__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
			case WarmachinerosterPackage.ROSTER__POINT_VALUE:
				return getPointValue() != POINT_VALUE_EDEFAULT;
			case WarmachinerosterPackage.ROSTER__MAX_POINT_VALUE:
				return maxPointValue != MAX_POINT_VALUE_EDEFAULT;
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (name: ");
		result.append(name);
		result.append(", maxPointValue: ");
		result.append(maxPointValue);
		result.append(')');
		return result.toString();
	}

} //RosterImpl
